import { leftName, rightName } from '@/config/localKey'

export const getMonthName = (date: number) => {
  const month = new Date(date).getMonth() + 1
  switch (month) {
    case 1:
      return 'Jan'
    case 2:
      return 'Feb'
    case 3:
      return 'Mar'
    case 4:
      return 'Apr'
    case 5:
      return 'May'
    case 6:
      return 'Jun'
    case 7:
      return 'Jul'
    case 8:
      return 'Aug'
    case 9:
      return 'Sep'
    case 10:
      return 'Oct'
    case 11:
      return 'Nov'
    case 12:
      return 'Dec'
    default:
      return ''
  }
}

export const getDayAndYear = (date: number) => {
  const day = new Date(date).getDate()
  const year = new Date(date).getFullYear()
  const formattedDay = day < 10 ? `0${day}` : `${day}`
  return `${formattedDay}-${year}`
}

export const formatDate = (date: number) => {
  const year = new Date(date).getFullYear()
  const month = new Date(date).getMonth() + 1
  const day = new Date(date).getDate()
  const formattedDay = day < 10 ? `0${day}` : `${day}`
  const formattedMonth = month < 10 ? `0${month}` : `${month}`
  return `${year}-${formattedMonth}-${formattedDay}`
}

export const getTomorrowMidnightTimestamp = () => {
  const today = new Date()
  today.setDate(today.getDate() + 1)
  today.setHours(0, 0, 0, 0)
  return today.getTime()
}

export const getCurrentMonthFirstDayTimestamp = (date = new Date()) => {
  // 创建一个新的日期对象，设置为当前月份的1号
  const firstDay = new Date(date.getFullYear(), date.getMonth(), 1)
  // 设置时间为0点0分0秒0毫秒
  firstDay.setHours(0, 0, 0, 0)
  // 返回时间戳（毫秒）
  return firstDay.getTime()
}

export const getCurrentMonthLastDayTimestamp = (date = new Date()) => {
  // 创建一个新的日期对象，设置为下个月的0号（即当月的最后一天）
  const lastDay = new Date(date.getFullYear(), date.getMonth() + 1, 0)
  // 设置时间为23点59分59秒999毫秒
  lastDay.setHours(23, 59, 59, 999)
  // 返回时间戳（毫秒）
  return lastDay.getTime()
}

export const getCurrentDayMidnightTimestamp = (date = new Date()) => {
  // 设置时间为0点0分0秒0毫秒
  date.setHours(0, 0, 0, 0)
  // 返回时间戳（毫秒）
  return date.getTime()
}

export const formatTime = (date: number) => {
  const hours = new Date(date).getHours()
  const minutes = new Date(date).getMinutes()
  const seconds = new Date(date).getSeconds()
  return `${hours < 10 ? '0' + hours : hours}:${minutes < 10 ? '0' + minutes : minutes}:${seconds < 10 ? '0' + seconds : seconds}`
}

// 随机生成昵称
export const generateRandomNickname = () => {
  // 从leftName数组中随机选择一个积极向上的单词
  const randomLeftIndex = Math.floor(Math.random() * leftName.length)
  const leftWord = leftName[randomLeftIndex]
  
  // 从rightName数组中随机选择一个动物单词
  const randomRightIndex = Math.floor(Math.random() * rightName.length)
  const rightWord = rightName[randomRightIndex]
  
  // 拼接并返回昵称
  return `${leftWord} ${rightWord}`
}

